package com.zx.map.dao.impl;

import com.zx.map.dao.EncashLogDao;
import com.zx.map.dao.mapper.EncashLogMapper;
import com.zx.map.dao.model.EncashLog;
import com.zx.map.dao.model.EncashLogExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: 14-3-1
 * Time: 上午10:54
 * To change this template use File | Settings | File Templates.
 */
@Component("encashLogDao")
public class EncashLogImpl implements EncashLogDao {

    @Autowired
    private EncashLogMapper mapper;

    /**
     * 新增
     */
    public String add(EncashLog encashLog) throws DataAccessException {
        int column = mapper.insert(encashLog);
        if (column != 1) {
            throw new RuntimeException("");
        }
        return encashLog.getEncashId();
    }

    /**
     * 修改
     *
     * @param encashLog
     * @return
     * @throws org.springframework.dao.DataAccessException
     */
    public String update(EncashLog encashLog) throws DataAccessException {
        int column = mapper.updateByPrimaryKeySelective(encashLog);
        if (column != 1) {
            throw new RuntimeException("");
        }
        return encashLog.getEncashId();
    }

    /**
     * 删除
     */
    public void delete(EncashLog encashLog) throws DataAccessException {
        int column = mapper.deleteByPrimaryKey(encashLog.getEncashId());
        if (column != 1) {
            throw new RuntimeException("");
        }
    }

    /**
     *
     */
    public List<EncashLog> getListByExample(EncashLogExample example)
            throws DataAccessException {
        return mapper.selectByExample(example);
    }

    /**
     *
     */
    public int countListByExample(EncashLogExample example)
            throws DataAccessException {
        return mapper.countByExample(example);
    }

    /**
     * 根据筛选的记录 更新某个字段
     */
    public void updateByExample(EncashLog encashLog, EncashLogExample example)
            throws DataAccessException {
        mapper.updateByExampleSelective(encashLog, example);
    }

    /**
     * 分页查找
     */
    public List<EncashLog> getPageByExample(int pageSize, int pageBegin,
                                            EncashLogExample example) throws DataAccessException {
        return mapper.getPageByModel(pageSize, pageBegin, example);
    }

	@Override
	public double getSettleAmt(EncashLogExample example)
			throws DataAccessException {
		return mapper.getSettleAmt(example);
	}
}
